package com.example.wallpaperapp.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

public class TitleFragmentPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> mFragmentList;
    private String[] titles;

    public TitleFragmentPagerAdapter(@NonNull FragmentManager mFragmentList, List<Fragment> fragmentList) {
        super(mFragmentList);
        this.mFragmentList= fragmentList;

    }
    public TitleFragmentPagerAdapter(@NonNull FragmentManager mFragmentList, List<Fragment> fragmentList,String[] titles) {
        super(mFragmentList);
        this.mFragmentList= fragmentList;
        this.titles=titles;

    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        Fragment fragment;
        if (position < mFragmentList.size()) {
            fragment = mFragmentList.get(position);
        } else {
            fragment = mFragmentList.get(0);
        }
        return fragment;
    }


    @Override
    public int getCount() {
        return mFragmentList.size();
    }
    public CharSequence getPageTitle(int position) {
        if (titles != null && titles.length > 0)
            return titles[position];
        return null;
    }
}
